from urllib.request import *
from urllib.parse import *
from fake_useragent import *

# 携带cookie的使用

form_data = {
    "username": "username",
    "password": "password"
}
headers = {
    "User-agent": UserAgent().chrome,
}
# cookie
processor = HTTPCookieProcessor()
opener = build_opener(processor)
# 登录
login_url = "https://www.w3cschool.cn/checklogin_1"
request = Request(login_url, data=urlencode(form_data).encode(), headers=headers)
opener.open(request)

# 访问页面
info_url = "https://www.w3cschool.cn/my"
request = Request(info_url, headers=headers)
response = opener.open(request)
print(response.read().decode())

